using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GeoFramework.Examples
{
    public partial class WorkingWithEmulatorsForm : Form
    {
        public WorkingWithEmulatorsForm()
        {
            InitializeComponent();

            /* To use a GPS device emulator, we simply point NmeaInterpreter classes
             * to the emulator classes.  GPS.NET emulators behave as Stream objects,
             * allowing them to easily replace actual streams from hardware such as serial
             * ports or Bluetooth.
             */
            EarthmateInterpreter.BaseStream =
                new GeoFramework.Gps.Emulators.DeLormeEarthmateUsbEmulator();

            eTrexInterpreter.BaseStream =
                new GeoFramework.Gps.Emulators.GarminEtrexVistaNmeaEmulator();

            // Start both of the interpreters
            EarthmateInterpreter.Start();
            eTrexInterpreter.Start();
        }

        private void EarthmateInterpreter_SentenceReceived(object sender, GeoFramework.Gps.Nmea.NmeaSentenceEventArgs e)
        {
            // Add the emulated sentence to the list box
            EarthmateSentencesListBox.Items.Add(e.Sentence.ToString());
            // Make sure the last item is always visible
            EarthmateSentencesListBox.SelectedIndex = EarthmateSentencesListBox.Items.Count - 1;
        }

        private void eTrexInterpreter_SentenceReceived(object sender, GeoFramework.Gps.Nmea.NmeaSentenceEventArgs e)
        {
            // Add the emulated sentence to the list box
            eTrexSentencesListBox.Items.Add(e.Sentence.ToString());
            // Make sure the last item is always visible
            eTrexSentencesListBox.SelectedIndex = eTrexSentencesListBox.Items.Count - 1;
        }
    }
}